import store from '@/store'

export default {
  inserted(el, binding, vnode) {
    const { value } = binding
    const roles = store.getters && store.getters.roles && [localStorage.getItem("roleName")]
    //console.log('权限配置',binding)
    if (value && value instanceof Array && value.length > 0) {
      const permissionRoles = value
      
      const hasPermission = roles.some(role => {
        //console.log('允许',permissionRoles.includes(role))
        return permissionRoles.includes(role)
      })
      if (!hasPermission) {
        //console.log('禁止')
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
     // console.log('这里到了吗')
      throw new Error(`需要的角色!像v-permission = "['超级管理员','管理员']"`)
    }
  }
}
